//
// Created on 2022/12/9.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".











#ifndef classification_Detection_H
#define classification_Detection_H

#include <string.h>
#include <iostream>

#include <string>
#include <vector>

class Detection {
  public:
    // Constructor
    Detection(int srcImageWidth, int srcImgHeight);

    ~Detection();

    
    
    
    
    
    
    std::string getDecodeResult(float *branchScores, float *branchBoxData);

    struct NormalBox {
        float y;
        float x;
        float h;
        float w;
    };

    struct YXBoxes {
        float ymin;
        float xmin;
        float ymax;
        float xmax;
    };

    struct Product {
        int x;
        int y;
    };

    struct WHBox {
        float boxw;
        float boxh;
    };

  private:
    std::vector<struct NormalBox> mDefaultBoxes;
    int inputImageHeight;
    int inputImageWidth;

    void getDefaultBoxes();

    void ssd_boxes_decode(const NormalBox *boxes,
                          YXBoxes *const decode_boxes,
                          const float scale0 = 0.1, const float scale = 0.2,
                          const int count = 1917);

    void nonMaximumSuppression(const YXBoxes *const decoded_boxes, const float *const scores,
                               const std::vector<int> &in_indexes, std::vector<int> *out_indexes_p,
                               const float nmsThreshold = 0.6,
                               const int count = 1917, const int max_results = 100);

    double IOU(float r1[4], float r2[4]);

    // variables
    struct network {
        int model_input_height = 300;
        int model_input_width = 300;

        int num_default[6] = {3, 6, 6, 6, 6, 6};
        int feature_size[6] = {19, 10, 5, 3, 2, 1};
        double min_scale = 0.2;
        double max_scale = 0.95;
        float steps[6] = {16, 32, 64, 100, 150, 300};
        float prior_scaling[2] = {0.1, 0.2};
        float gamma = 2.0;
        float alpha = 0.75;
        int aspect_ratios[6][2] = {{2,0},
        {2,3},
        {2,3},
        {2,3},
        {2,3},
        {2,3}};
    } config;
    
    float g_thres_map[81] = {
    0,
        0.635,
        0.627,
        0.589,
        0.585,
        0.648,
        0.664,
        0.655,
        0.481,
        0.529,
        0.611,
        0.641,
        0.774,
        0.549,
        0.513,
        0.652,
        0.552,
        0.590,
        0.650,
        0.575,
        0.583,
        0.650,
        0.656,
        0.696,
        0.653,
        0.438,
        0.515,
        0.459,
        0.561,
        0.545,
        0.635,
        0.540,
        0.560,
        0.721,
        0.544,
        0.548,
        0.511,
        0.611,
        0.592,
        0.542,
        0.512,
        0.635,
        0.531,
        0.437,
        0.525,
        0.445,
        0.484,
        0.546,
        0.490,
        0.581,
        0.566,
        0.516,
        0.445,
        0.541,
        0.613,
        0.560,
        0.483,
        0.509,
        0.464,
        0.543,
        0.538,
        0.490,
        0.576,
        0.617,
        0.577,
        0.595,
        0.640,
        0.585,
        0.598,
        0.592,
        0.514,
        0.397,
        0.592,
        0.504,
        0.548,
        0.642,
        0.581,
        0.497,
        0.545,
        0.154,
        0.580
    };
    
    std::string object_detection[81] = {
    "背景","人","自行车","汽车","摩托车","飞机","公共汽车",
    "火车",
    "卡车",
    "船",
    "交通灯",
    "消防栓",
    "停车标志",
    "停车计时器",
    "长凳",
    "鸟",
    "猫",
    "狗",
    "马",
    "绵羊",
    "牛",
    "大象",
    "熊",
    "斑马",
    "长颈鹿",
    "背包",
    "雨伞",
    "手提包",
    "领带",
    "手提箱",
    "飞盘",
    "滑雪板",
    "雪板",
    "运动用的球",
    "风筝",
    "棒球棒",
    "棒球手套",
    "滑板",
    "冲浪板",
    "网球拍",
    "瓶子",
    "酒杯",
    "杯",
    "叉子",
    "刀",
    "勺子",
    "碗",
    "香蕉",
    "苹果",
    "三明治",
    "橙子",
    "西兰花",
    "胡萝卜",
    "热狗",
    "披萨",
    "甜甜圈",
    "蛋糕",
    "椅子",
    "沙发",
    "盆栽植物",
    "床",
    "餐桌",
    "厕所",
    "电视",
    "笔记本电脑",
    "鼠标",
    "遥控器",
    "键盘",
    "手机",
    "微波炉",
    "烤箱",
    "烤面包机",
    "水槽",
    "冰箱",
    "书",
    "时钟",
    "花瓶",
    "剪刀",
    "泰迪熊",
    "吹风机",
    "牙刷"};
};
#endif //classification_Detection_H
